package org.jeecg.modules.gis.service;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.gis.entity.GisRoadNetwork;
import org.jeecg.modules.gis.util.network.RoadNetworkModel;
import org.jeecg.modules.gis.vo.RoutePraVo;
import org.locationtech.jts.geom.GeometryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

@Service
public class RouteService {

    @Autowired
    private IGisRoadNetworkService gisRoadNetworkService;
    @Autowired
    private GeometryFactory geometryFactory;

    private RoadNetworkModel roadNetworkModel;

    @PostConstruct
    public void init() {
        List<GisRoadNetwork> roadList = gisRoadNetworkService.list();
        this.roadNetworkModel = new RoadNetworkModel(roadList, geometryFactory);
    }

    public JSONObject getShortestRoute(RoutePraVo vo) throws Exception {
        return roadNetworkModel.getShortestRoute(vo);
    }
}
